<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitActivityTicket extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 扭蛋机
        Schema::create('activity_tickets', function (Blueprint $table) {

            $table->comment = '活动剩余次数';

            $table->increments('id');
            $table->uuid('uuid')->index() ;


            $table->integer('user_id')->index()->comment('用户id'); // 标题
            $table->integer('node_id')->index()->comment('活动id'); // 标题
            $table->uuid('node_uuid')->index()->comment('活动uuid'); // 标题
            $table->char('node_type', 20)->index()->comment('活动类型'); // 标题

            $table->integer('total')->comment('剩余次数'); // 标题

            $table->softDeletes();
            $table->timestamps();
        });

        // 扭蛋机
        Schema::create('activity_ticket_records', function (Blueprint $table) {

            $table->comment = '活动剩余次数记录';

            $table->increments('id');
            $table->uuid('uuid')->index() ;


            $table->integer('user_id')->index()->comment('用户id'); // 标题
            $table->integer('node_id')->index()->comment('活动id'); // 标题
            $table->uuid('node_uuid')->index()->comment('活动uuid'); // 标题
            $table->char('node_type', 20)->index()->comment('活动类型'); // 标题


            $table->boolean('type')->default(1)->index()->comment('1为收入 2为流出'); // 标题
            $table->integer('total')->comment('剩余次数'); // 标题
            $table->integer('after_total')->comment('流水后的剩余数量'); // 标题

            $table->string('description')->nullable()->comment('变动描述'); // 标题


            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::disableForeignKeyConstraints();
        Schema::dropIfExists('activity_tickets');
        Schema::dropIfExists('activity_ticket_records');
    }
}
